//
//  ChatSystemInfo.m
//  SportSocial
//
//  Created by yull on 15/1/28.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "ChatSystemInfo.h"

@implementation ChatSystemInfo

+ (instancetype)systemInfoWithFriendMsg:(FriendNotifyMessage *)friendMsg
{
    //消息类型  1 添加好友申请  2:拒绝添加好友  3添加好友  4 删除好友：发送给userId
    //required int32 msgType = 1;
    //消息id  收到了就回回来
    //required int64 msgId = 2;
    //required int64 userId = 3;
    //required string name = 4;
    //消息key
    //required string key = 5;
    ChatSystemInfo *chatInfo = [[ChatSystemInfo alloc] init];
    chatInfo.infoType = SystemInfoTypeFriend;
    chatInfo.friendType = friendMsg.msgType;
    chatInfo.time = [[NSDate date] timeIntervalSince1970] * 1000;
    chatInfo.userName = friendMsg.name;
    chatInfo.userId = friendMsg.userId;
    chatInfo.content = [self getContentWithFriendType:chatInfo.friendType];
    chatInfo.key = friendMsg.key;
    return chatInfo;
}

+ (instancetype)systemInfowithGroupMsg:(GroupNotifyMessage *)groupMsg
{
    ChatSystemInfo *chatInfo = [[ChatSystemInfo alloc] init];
    chatInfo.infoType = SystemInfoTypeGroup;
    chatInfo.groupType = groupMsg.msgType;
    chatInfo.userId = groupMsg.userId;
    chatInfo.userName = groupMsg.userName;
    chatInfo.groupId = groupMsg.groupId;
    chatInfo.groupName = groupMsg.groupName;
    chatInfo.createId = groupMsg.createId;
    chatInfo.createName = groupMsg.createName;
    chatInfo.key = groupMsg.key;
    chatInfo.msgId = groupMsg.msgId;
    chatInfo.icon = groupMsg.icon;
    //chatInfo.par = groupMsg.parList;
    
    chatInfo.time = [[NSDate date] timeIntervalSince1970] * 1000;
    chatInfo.content = [self getContentWithSystemGroupInfo:chatInfo];
    return chatInfo;
}

+ (instancetype)systemInfoWithResultSet:(FMResultSet *)resultSet
{
    ChatSystemInfo *chatInfo = [[ChatSystemInfo alloc] init];
    chatInfo.infoType = [resultSet intForColumn:@"infoType"];
    chatInfo.friendType = [resultSet intForColumn:@"friendType"];
    chatInfo.groupType = [resultSet intForColumn:@"groupType"];
    chatInfo.time = [resultSet longLongIntForColumn:@"time"];
    chatInfo.userName = [resultSet stringForColumn:@"userName"];
    chatInfo.userId = [resultSet longLongIntForColumn:@"userId"];
    chatInfo.groupName = [resultSet stringForColumn:@"groupName"];
    chatInfo.groupId = [resultSet longLongIntForColumn:@"groupId"];
    chatInfo.createName = [resultSet stringForColumn:@"createName"];
    chatInfo.createId = [resultSet longLongIntForColumn:@"createId"];
    chatInfo.content = [resultSet stringForColumn:@"content"];
    chatInfo.icon = [resultSet stringForColumn:@"icon"];
    chatInfo.key = [resultSet stringForColumn:@"key"];
    chatInfo.msgId = [resultSet longLongIntForColumn:@"msgId"];
    chatInfo.dbId = [resultSet intForColumn:@"id"];
    return chatInfo;
}

+ (NSString *)getContentWithFriendType:(SystemInfoFriendType)friendType
{
    switch (friendType) {
        case SystemInfoFriendTypeAdd:
            return @"同意添加您为好友";
        case SystemInfoFriendTypeApply:
            return @"请求添加您为好友";
        case SystemInfoFriendTypeDelete:
            return @"解除您的好友关系";
        case SystemInfoFriendTypeRefuse:
            return @"拒绝添加您为好友";
        default:
            return @"";
    }
}

+ (NSString *)getContentWithSystemGroupInfo:(ChatSystemInfo *)systemInfo
{
    switch (systemInfo.groupType) {
        case SystemInfoGroupTypeApply:
            return [[NSString alloc] initWithFormat:@"%@申请加入%@",systemInfo.userName,systemInfo.groupName];
        case SystemInfoGroupTypeRefuse:
            return [[NSString alloc] initWithFormat:@"%@的管理员%@拒绝了您的加入",systemInfo.groupName,systemInfo.createName];
        case SystemInfoGroupTypeInvite:
            return [[NSString alloc] initWithFormat:@"%@的管理员%@邀请您加入",systemInfo.groupName,systemInfo.createName];
        case SystemInfoGroupTypeRefuseInvite:
            return [[NSString alloc] initWithFormat:@"您邀请%@加入%@被拒绝了",systemInfo.userName,systemInfo.groupName];
        case SystemInfoGroupTypeJoin:
            return [[NSString alloc] initWithFormat:@"%@加入了%@",systemInfo.userName,systemInfo.groupName];
        case SystemInfoGroupTypeKickout:
            return [[NSString alloc] initWithFormat:@"您被%@的管理员%@踢出了",systemInfo.groupName,systemInfo.createName];
        case SystemInfoGroupTypeCheckFinish:
            return [[NSString alloc] initWithFormat:@"您创建的群【%@】已通过审核",systemInfo.groupName];
        case SystemInfoGroupTypeCheckFail:
            return [[NSString alloc] initWithFormat:@"您创建的群【%@】未通过审核",systemInfo.groupName];
        case SystemInfoGroupTypeDismiss:
            return [[NSString alloc] initWithFormat:@"%@被群主解散了",systemInfo.groupName];
        default:
            return @"";
    }
}
@end
